import { createStore } from 'vuex'
import getters from './getters'

// you do not need `import app from './modules/app'`
// it will auto require all vuex module from modules file
const modulesFiles = import.meta.globEager('./modules/*.js')
const modules = Object.entries(modulesFiles).reduce((modules, [path, mod]) => {
  const moduleName = path.replace(/^\.\/modules\/(.*)\.\w+$/, '$1')
  modules[moduleName] = mod.default
  return modules
}, {})

const store = createStore({
  modules,
  getters
})
export default store
